﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Vowei.Core;
using Vowei.Core.Models;


namespace Vowei.Core.Models
{
    /// <summary>
    /// 表示一个里程碑
    /// </summary>
    [DataContract]
    public class Milestone : INamedTable, ISupportDefaultProperties, IDuration, IContainer<Milestone>, IScoped, ICommentable, IStatus
    {
        public Milestone()
        {
            this.FillDefaultProperties();
            Children = new List<Milestone>();
            Comments = new List<Comment>();
        }

        /// <summary>
        /// 项目开始的日期
        /// </summary>
        [Display(Name = "开始日期")]
        [DataMember]
        public DateTime? StartDate { get; set; }
        
        /// <summary>
        /// 计划中里程碑结束的时间
        /// </summary>
        [Display(Name = "计划结束日期")]
        [DataMember]
        public DateTime? DueDate { get; set; }

        /// <summary>
        /// 实际上里程碑结束的时间
        /// </summary>
        /// <remarks>
        /// 这个应该是根据里程碑里任务完成的数目而实现的
        /// </remarks>
        [Display(Name = "关闭时间")]
        [DataMember]
        public DateTime? ClosedDate { get; set; }

        [Display(Name = "上次修改时间")]
        public DateTime LastModified
        {
            get;
            set;
        }

        [Display(Name = "最后修改人")]
        public string LastModifiedBy
        {
            get;
            set;
        }

        IQueryable ITableItemContainer.Children
        {
            get
            {
                return Children.AsQueryable();
            }
        }

        [Display(Name = "子里程碑")]
        // public virtual List<Milestone> Children { get; private set; }
        public virtual List<Milestone> Children { get; set; }

        [Display(Name = "相关评论")]
        // public virtual List<Comment> Comments { get; private set; }
        public virtual List<Comment> Comments { get; set; }
        
        #region ISupportDefaultProperties Members
        [Display(Name = "创建日期")]
        public DateTime OpenDate
        {
            get;
            set;
        }

        [Display(Name = "创建人")]
        public string Reporter
        {
            get;
            set;
        }

        #endregion

        [DataMember]
        [Display(Name = "在指定的里程碑内完成")]
        public Milestone BelongsToMilestone
        {
            get;
            set;
        }
        
        public Guid? BelongsToMilestoneId { get; set; }
        
        [DataMember]
        public Guid ID
        {
            get;
            set;
        }

        [Display(Name = "标题")]
        [DataMember]
        public string Title
        {
            get;
            set;
        }

        [Display(Name = "状态")]
        public string Status
        {
            get;
            set;
        }

        [Display(Name = "进度")]
        public float Progress
        {
            get;
            set;
        }
    }

}
